<!DOCTYPE html>
<html>

	<head>
		<meta charset="UTF-8">
		<title></title>
		<script type="text/javascript" src="../js/angular.min.js"></script>
		<script type="text/javascript" src="../js/angular-route.min.js"></script>
	</head>

	<body>
		<!--ng-app="myapp"定义了一个模块,限定angular作用域-->
		<div ng-app="myapp" ng-controller="myctrl">
			<!--ng-model模型作用-->
			<input type="text" ng-model="name" />
			<input type="button" value="清空" ng-click="clearVal()" />
			<div>
				<!--{{}}等价于ng-bind用于数据显示-->
				Hello,{{name}}
			</div>
			<!--遍历-->
			<div>
				<table border="1">
					<tr>
						<td>序号</td>
						<td>品名</td>
						<td>单价</td>
					</tr>
					<tr ng-repeat="product in products">
						<td>{{$index}}</td>
						<td>{{product.name}}</td>
						<td>{{product.price}}</td>
					</tr>
				</table>
			</div>
		</div>
		<!--Controller控制器是js代码
			Model模型是name属性
			View视图是{{name}}-->
		<script type="text/javascript">
			//初始化myapp模块
			var myapp = angular.module("myapp", []);

			//定义模块的控制器
			//依赖注入,$scope作用域对象,操作当前作用域视图
			myapp.controller("myctrl", ["$scope", function($scope) {
				//对模型进行初始化赋值
				$scope.name = "黑马你好"
				//绑定点击事件
				$scope.clearVal = function() {
					$scope.name = "";
				}
				//给数组/集合赋值
				$scope.products = [{
					name: '苹果',
					price: 5000
				}, {
					name: '梨子',
					price: 10000
				}]
			}]);
		</script>
	</body>

</html>